woocommerce get product id

52

get product price woocommerce of specific id -

$product = wc_get_product( $post_id );

$product->get_regular_price();
$product->get_sale_price();
$product->get_price();

woocommerce get product id -

global $product;
$product->get_id();

woocommerce get product category name by id -

$id = 42;
if( $term = get_term_by( 'id', $id, 'product_cat' ) ){
    echo $term->name;
}

woocommerce get product categories -

$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
    $product_cat_id[] = $term->term_id;
}

Comments

Submit
0 Comments